home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / Pascal Demos / Button / Modal3.p < prev    next >
Text File  |  1996-01-24  |  4KB  |  163 lines

  1. unit Modal3;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types, MixedMode, QuickDraw, Windows, Dialogs, OSUtils, TransSkel, ButtonGlobals;
  7.  
  8.  
  9.     procedure DoModal3;
  10.  
  11. implementation
  12.  
  13.     const
  14.  
  15.         iPushDismiss = 1;
  16.         iPushButton1 = 2;
  17.         iPushButton2 = 3;
  18.         iPushButton3 = 4;
  19.         iRadioStaticText = 5;
  20.         iRadioButton1 = 6;
  21.         iRadioButton2 = 7;
  22.         iRadioButton3 = 8;
  23.         iRadioNone = 9;
  24.         iCheckStaticText = 10;
  25.         iCheckButton1 = 11;
  26.         iCheckButton2 = 12;
  27.         iCheckButton3 = 13;
  28.         iOutline = 14;
  29.  
  30.  
  31.     var
  32.  
  33.         defaultButton: Integer;
  34.  
  35.         drawProc: UserItemUPP;
  36.  
  37.  
  38. {--------------------------------------------------------------------}
  39. { Dialog 3 procedures }
  40. {--------------------------------------------------------------------}
  41.  
  42. procedure OutlineButton (dlog: DialogPtr; item: Integer);
  43. begin
  44.     SkelDrawButtonOutline(SkelGetDlogCtl(dlog, defaultButton));
  45. end;
  46.  
  47.  
  48. procedure InstallOutliner (dlog: DialogPtr; item: Integer);
  49. var
  50.     r: Rect;
  51. begin
  52.     SkelGetDlogRect(dlog, item, r);
  53.     InsetRect(r, -4, -4);
  54.     SkelSetDlogRect(dlog, iOutline, r);
  55.     SkelSetDlogProc(dlog, iOutline, drawProc);
  56.     SkelDrawButtonOutline(SkelGetDlogCtl(dlog, defaultButton));
  57. end;
  58.  
  59.  
  60. procedure RemoveOutliner (dlog: DialogPtr);
  61. begin
  62.     SkelSetDlogProc(dlog, iOutline, nil);
  63.     SkelEraseButtonOutline(SkelGetDlogCtl(dlog, defaultButton));
  64. end;
  65.  
  66.  
  67. procedure SetDefaultButton (dlog: DialogPtr; item: Integer);
  68. begin
  69.     if (defaultButton <> 0) then
  70.         RemoveOutliner(dlog);
  71.     defaultButton := item;
  72.     if (defaultButton <> 0) then
  73.         InstallOutliner(dlog, defaultButton);
  74. end;
  75.  
  76.  
  77. procedure DoModal3;
  78. var
  79.     filter: ModalFilterProcPtr;
  80.     dlog: DialogPtr;
  81.     savePort: GrafPtr;
  82.     item: Integer;
  83.     value: Integer;
  84.     hilite: Integer;
  85.     loop: Boolean;
  86. begin
  87.     dlog := GetNewDialog(modal3Res, nil, WindowPtr(-1));
  88.     if (dlog = DialogPtr(nil)) then
  89.         begin
  90.             SysBeep(1);
  91.             exit(DoModal3);
  92.         end;
  93.  
  94.     SkelPositionWindow(dlog, skelPositionOnMainDevice, horizRatio, vertRatio);
  95.  
  96.     GetPort(savePort);
  97.     SetPort(dlog);
  98.  
  99.     {
  100.         Set up a variable to point to the outline drawing procedure.  For 68K code
  101.         this is just a direct pointer to OutlineButton().  For PowerPC code it is a
  102.         routine descriptor into which the address of OutlineButton() is stuffed.
  103.     }
  104.  
  105.     drawProc := NewUserItemProc (@OutlineButton);
  106.  
  107.     { should really check whether or not drawProc is nil! }
  108.  
  109.     SetDefaultButton(dlog, iPushButton1);
  110.     SkelSetDlogCtlValue(dlog, iCheckButton1, 1);
  111.     SkelSetDlogCtlValue(dlog, iCheckButton2, 1);
  112.     SkelSetDlogCtlValue(dlog, iCheckButton3, 1);
  113.     SkelSetDlogRadioButtonSet(dlog, iRadioButton1, iRadioNone, iRadioButton1);
  114.  
  115.     ShowWindow(dlog);
  116.  
  117.     loop := true;
  118.     while (loop) do
  119.         begin
  120.             filter := SkelDlogFilter(nil, false);
  121.             SkelDlogDefaultItem(defaultButton); { turns off if zero }
  122.             ModalDialog(filter, item);
  123.             SkelRmveDlogFilter;
  124.             case item of
  125.                 iPushDismiss: 
  126.                     loop := false;
  127.                 iPushButton1, iPushButton2, iPushButton3: 
  128.                     begin
  129.                         { ignore hits in these items }
  130.                     end;
  131.                 iRadioButton1, iRadioButton2, iRadioButton3: 
  132.                     begin
  133.                         SkelSetDlogRadioButtonSet(dlog, iRadioButton1, iRadioNone, item);
  134.                         { remap item number from radio button range into pushbutton range }
  135.                         item := item + iPushButton1 - iRadioButton1;
  136.                         SetDefaultButton(dlog, item);
  137.                     end;
  138.                 iRadioNone:
  139.                     begin
  140.                         SkelSetDlogRadioButtonSet(dlog, iRadioButton1, iRadioNone, item);
  141.                         SetDefaultButton(dlog, 0);    { no default button }
  142.                     end;
  143.                 iCheckButton1, iCheckButton2, iCheckButton3: 
  144.                     begin
  145.                         value := SkelToggleDlogCtlValue(dlog, item);
  146.                         if (value <> 0) then
  147.                             hilite := normalHilite
  148.                         else
  149.                             hilite := dimHilite;
  150.                         { remap item number from checkbox range into pushbutton range }
  151.                         item := item + iPushButton1 - iCheckButton1;
  152.                         if (SkelSetDlogCtlHilite(dlog, item, hilite) and (item = defaultButton)) then
  153.                             SkelDrawButtonOutline(SkelGetDlogCtl(dlog, item));
  154.                     end;
  155.             end;
  156.         end;
  157.  
  158.     DisposeRoutineDescriptor (drawProc);
  159.     DisposeDialog(dlog);
  160.     SetPort(savePort);
  161. end;
  162.  
  163. end.